﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NuMetaheuristics.Utility
{
    public class TypeInstanceDictionary
    {
        public Dictionary<Type, List<object>> Instances { get; private set; }

        public TypeInstanceDictionary()
        {
            Instances = new Dictionary<Type, List<object>>();
        }

        public void AddObject(object obj)
        {
            if (Instances.ContainsKey(obj.GetType()))
            {
                Instances[obj.GetType()].Add(obj);
            }
            else
            {
                List<object> objects = new List<object>();
                objects.Add(obj);

                Instances.Add(obj.GetType(), objects);
            }
        }

        public bool TryGetObjects(Type type, out List<object> objects)
        {
            return Instances.TryGetValue(type, out objects);
        }
    }
}
